@extends('base')

@section('content')
    <div class="layui-card">
        <div class="layui-card-header layuiadmin-card-header-auto">
            <form class="layui-form" action="{{route("caiwu.invoice")}}">
                <div class="layui-btn-group">
                    @can('caiwu.invoice.destroy')
                        <button type="button" class="layui-btn layui-btn-sm layui-btn-danger" data-url="{{route('caiwu.invoice.destroy')}}" id="listDelete">删除</button>
                    @endcan
                    @can('caiwu.invoice.create')
                        <a class="layui-btn layui-btn-sm" id="addBtn">添加</a>
                    @endcan
                    <button type="button" lay-submit lay-filter="search" class="layui-btn layui-btn-sm" >搜索</button>
                </div>
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label for="" class="layui-form-label">公司名称：</label>
                        <div class="layui-input-block" style="width: 275px">
                            <input type="text" name="name" placeholder="请输入名称" class="layui-input" >
                        </div>
                    </div>
                </div>
            </form>
        </div>
        <div class="layui-card-body">
            <table id="dataTable" lay-filter="dataTable"></table>
        </div>
    </div>
@endsection

@section('script')
    <script>
        layui.use(['layer','table','form','laydate','upload'],function () {
            var $ = layui.jquery;
            var layer = layui.layer;
            var form = layui.form;
            var table = layui.table;
            var laydate = layui.laydate;
            var upload = layui.upload;
            //用户表格初始化
            var dataTable = table.render({
                elem: '#dataTable'
                ,height: 'full-140'
                ,url: "{{ route('caiwu.invoice') }}" //数据接口
                ,page: true //开启分页
                ,cols: [[ //表头
                    {checkbox: true}
                    ,{field: 'type', title: '抬头类型',templet:function (d) {
                            return d.type===1?'企业单位':'个人/非企业单位'
                        }}
                    ,{field: 'name', title: '公司名称'}
                    ,{field: 'num', title: '公司税号'}
                    ,{field: 'money', title: '总金额'}
                    ,{field: 'user_nickname', title: '申请人'}
                    ,{field: 'created_at', title: '申请时间'}
                    ,{field: 'check_status', title: '审核状态',templet:function (d) {
                            if (d.check_status===1){
                                return '<span class="layui-badge" lay-event="check">待审核</span>'
                            }else if (d.check_status===2){
                                return '<span class="layui-badge layui-bg-black" lay-event="check">未通过</span>'
                            }else if (d.check_status===3){
                                return '<span class="layui-badge layui-bg-green" lay-event="check">通过</span>'
                            }
                        },width: 100}
                ]]
            });

            //监听工具条
            table.on('tool(dataTable)', function(obj){ //注：tool是工具条事件名，dataTable是table原始容器的属性 lay-filter="对应的值"
                var data = obj.data //获得当前行数据
                    ,layEvent = obj.event; //获得 lay-event 对应的值
                if (layEvent === 'check'){
                    layer.open({
                        type: 2,
                        title: "审核",
                        shadeClose: true,
                        area: ["600px","600px"],
                        content: '/caiwu/invoice/check?id='+data.id,
                    })
                } else if(layEvent === 'show'){
                    layer.open({
                        type: 2,
                        title: "付款申请记录",
                        shadeClose: true,
                        area: ["90%","90%"],
                        content: '/caiwu/pay/show?order_id='+data.order_id,
                    })
                }
            });

            $("#addBtn").click(function () {
                layer.open({
                    type: 2,
                    title: "添加",
                    shadeClose: true,
                    area: ["80%","80%"],
                    content: "{{route("caiwu.invoice.create")}}",
                })
            })

        })
    </script>
@endsection
